home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / osrc.arc / IP.H < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-28  |  4.6 KB  |  150 lines

  1. #ifndef    NROUTE
  2.  
  3. #include "global.h"
  4. #include "timer.h"
  5.  
  6. #define    NROUTE    5    /* Number of hash chains in routing table */
  7.  
  8. extern int32 Ip_addr;    /* Our IP address for ICMP and source routing */
  9.  
  10. extern char Ip_ttl;    /* Default time-to-live for IP datagrams */
  11.  
  12. #define    IPVERSION    4
  13. /* IP header, INTERNAL representation */
  14. struct ip {
  15.     char version;        /* IP version number */
  16.     char tos;        /* Type of service */
  17.     int16 length;        /* Total length */
  18.     int16 id;        /* Identification */
  19.     int16 offset;        /* Fragment offset in bytes */
  20.     struct {
  21.         char df;    /* Don't fragment flag */
  22.         char mf;    /* More Fragments flag */
  23.     } flags;
  24.  
  25.     char ttl;        /* Time to live */
  26.     char protocol;        /* Protocol */
  27.     int32 source;        /* Source address */
  28.     int32 dest;        /* Destination address */
  29.     char options[44];    /* Options field */
  30.     int16 optlen;        /* Length of options field, bytes */
  31. };
  32. #define    NULLIP    (struct ip *)0
  33. #define    IPLEN    20    /* Length of standard IP header */
  34.  
  35. /* Fields in option type byte */
  36. #define    OPT_COPIED    0x80    /* Copied-on-fragmentation flag */
  37. #define    OPT_CLASS    0x60    /* Option class */
  38. #define    OPT_NUMBER    0x1f    /* Option number */
  39.  
  40. /* IP option numbers */
  41. #define    IP_EOL        0    /* End of options list */
  42. #define    IP_NOOP        1    /* No Operation */
  43. #define    IP_SECURITY    2    /* Security parameters */
  44. #define    IP_LSROUTE    3    /* Loose Source Routing */
  45. #define    IP_TIMESTAMP    4    /* Internet Timestamp */
  46. #define    IP_RROUTE    7    /* Record Route */
  47. #define    IP_STREAMID    8    /* Stream ID */
  48. #define    IP_SSROUTE    9    /* Strict Source Routing */
  49.  
  50. /* Timestamp option flags */
  51. #define    TS_ONLY        0    /* Time stamps only */
  52. #define    TS_ADDRESS    1    /* Addresses + Time stamps */
  53. #define    TS_PRESPEC    3    /* Prespecified addresses only */
  54.  
  55. /* IP routing table entry */
  56. struct route {
  57.     struct route *prev;    /* Linked list pointers */
  58.     struct route *next;
  59.     int32 target;        /* Target IP address */
  60.     int32 gateway;        /* IP address of local gateway for this target */
  61.     struct iface *iface;    /* Device interface structure */
  62.     int32 uses;        /* Usage count */
  63. };
  64. #define    NULLROUTE    (struct route *)0
  65. extern struct route *Routes[32][NROUTE];    /* Routing table */
  66. extern struct route R_default;            /* Default route entry */
  67.  
  68. /* Cache for the last-used routing entry, speeds up the common case where
  69.  * we handle a burst of packets to the same destination
  70.  */
  71. struct rt_cache {
  72.     int32 target;
  73.     struct route *route;
  74. };
  75. extern struct rt_cache Rt_cache;
  76.  
  77. /* Reassembly descriptor */
  78. struct reasm {
  79.     struct reasm *next;    /* Linked list pointers */
  80.     struct reasm *prev;
  81.     struct timer timer;    /* Reassembly timeout timer */
  82.     struct frag *fraglist;    /* Head of data fragment chain */
  83.     int16 length;        /* Entire datagram length, if known */
  84.     int32 source;        /* src/dest/id/protocol uniquely describe a datagram */
  85.     int32 dest;
  86.     int16 id;
  87.     char protocol;
  88. };
  89. #define    NULLREASM    (struct reasm *)0
  90.  
  91. /* Fragment descriptor in a reassembly list */
  92. struct frag {
  93.     struct frag *prev;    /* Previous fragment on list */
  94.     struct frag *next;    /* Next fragment */
  95.     struct mbuf *buf;    /* Actual fragment data */
  96.     int16 offset;        /* Starting offset of fragment */
  97.     int16 last;        /* Ending offset of fragment */
  98. };
  99. #define    NULLFRAG    (struct frag *)0
  100.  
  101. extern struct reasm *Reasmq;    /* The list of reassembly descriptors */
  102.  
  103. /* IP error logging counters */
  104. struct ip_stats {
  105.     long total;        /* Total packets received */
  106.     unsigned runt;        /* Smaller than minimum size */
  107.     unsigned length;    /* IP header length field too small */
  108.     unsigned version;    /* Wrong IP version */
  109.     unsigned checksum;    /* IP header checksum errors */
  110.     unsigned badproto;    /* Unsupported protocol */
  111. };
  112. /* Structure for handling raw IP user sockets */
  113. struct raw_ip {
  114.     struct raw_ip *prev;
  115.     struct raw_ip *next;
  116.  
  117.     struct mbuf *rcvq;    /* receive queue */
  118.     void (*r_upcall)();    /* Receive upcall routine */
  119.     char protocol;        /* Protocol */
  120.     int user;        /* User linkage */
  121. };
  122. #define    NULLRIP    ((struct raw_ip *)0)
  123.  
  124. extern struct ip_stats Ip_stats;
  125.  
  126. #if    defined(__STDC__) || defined(__TURBOC__)
  127. void del_ip(struct raw_ip *rrp);
  128. struct mbuf *htonip(struct ip *ip,struct mbuf *data);
  129. int ntohip(struct ip *ip,struct mbuf **bpp);
  130. int ip_route(struct mbuf *bp,int rxbroadcast);
  131. int rt_add(int32 target,unsigned int bits,int32 gateway,struct iface *iface);
  132. int rt_drop(int32 target,unsigned int bits);
  133. int16 ip_mtu(int32 addr);
  134. int16 cksum(struct pseudo_header *ph,struct mbuf *m,int16 len);
  135. #else
  136. void del_ip();
  137. struct mbuf *htonip();
  138. int ip_route();
  139. int rt_add();
  140. int rt_drop();
  141. int16 ip_mtu();
  142. int16 cksum();
  143. #endif
  144. struct raw_ip *raw_ip();
  145. void ip_recv(),tcp_input(),udp_input(),icmp_input();
  146.  
  147. #endif /* NROUTE */
  148.  
  149.  
  150.